package www.icomwell.com.viperdemo.Modules.List.UserInterface.Presenter;

import java.util.ArrayList;
import java.util.List;

import www.icomwell.com.viperdemo.Modules.List.ApplicationLogic.Interactor.ListInteractor;
import www.icomwell.com.viperdemo.Modules.List.ApplicationLogic.Interactor.ListInteractorOutput;
import www.icomwell.com.viperdemo.Modules.List.ApplicationLogic.Interactor.UpcomingItem;
import www.icomwell.com.viperdemo.Modules.List.ModuleInterface.ListModuleInterface;
import www.icomwell.com.viperdemo.Modules.List.UserInterface.View.ListViewInterface;

/**
 * Created by leeesven on 17/5/23.
 */

public class ListPresenter implements ListModuleInterface, ListInteractorOutput {

	private ListInteractor mListInteractor;
	private ListViewInterface listViewInterface;

	public ListPresenter(ListViewInterface listViewInterface) {
		mListInteractor = new ListInteractor(this);
		this.listViewInterface = listViewInterface;
	}

	@Override
	public void updateView() {
		mListInteractor.findUpcomingItems();
	}

	@Override
	public void foundUpcomingItems(List<UpcomingItem> upcomingItems) {
		this.listViewInterface.showUpcomingDisplayData(upcomingDisplayDataWithItems(upcomingItems));
	}

	private List<DisplayData> upcomingDisplayDataWithItems(List<UpcomingItem> upcomingItems){
		List<DisplayData> displayDatas = new ArrayList<>();
		for (UpcomingItem item : upcomingItems){
			DisplayData displayData = new DisplayData(item.getTitle(), item.getDate());
			displayDatas.add(displayData);
		}
		return displayDatas;
	}
}
